package me.keiwu.log.controller.rpc;

import me.keiwu.log.domain.LogLogin;
import me.keiwu.log.service.LogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by kei on 29/11/2017.
 */
@RestController
@RequestMapping("/rpc/log/login")
public class LoginRpcController {

    @Autowired
    private LogLoginService logLoginService;


    @ResponseBody
    @RequestMapping("/daily")
    public Page<LogLogin> dailyLogin(@RequestParam(required = false) String nickName,
                               @RequestParam(defaultValue = "0") Integer page,
                               @RequestParam(defaultValue = "10") Integer size) {
        return logLoginService.getDailyLogin(nickName, page, size);
    }

    @ResponseBody
    @RequestMapping("/history")
    public Page<LogLogin> historyLogin(@RequestParam(required = false) String nickName,
                             @RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size) {
        return logLoginService.getHistoryLogin(nickName, page, size);
    }


    @ResponseBody
    @RequestMapping("/log")
    public void logLogin(Long userId, String nickName, String channel, Integer loginTime) {
        logLoginService.logLogin(userId, nickName, channel, loginTime);
    }


}
